package com.itheima.myhashsettest;

import java.util.TreeSet;

public class 随堂练习2 {
    public static void main(String[] args) {
        TreeSet<Student> treeSet = new TreeSet<>(/*(o1, o2) -> {
            int result = o1.getSumScore() - o2.getSumScore();
            result = result == 0 ? o1.getyScore() - o2.getyScore() : result;
            result = result == 0 ? o1.getmScore() - o2.getmScore() : result;
            result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
            return result;
        }*/);

        Student student1 = new Student("张三",88,99,100);
        Student student2 = new Student("李斯",97,86,79);
        Student student3 = new Student("王武",69,89,99);
        treeSet.add(student1);
        treeSet.add(student2);
        treeSet.add(student3);



        for (Student stu : treeSet) {
            System.out.println(stu.toString());
        }
    }
}

class Student implements Comparable<Student>{
    private String name;
    private int yScore;
    private int mScore;
    private int EnglishScore;

    public Student() {
    }

    public Student(String name, int yScore, int mScore, int englishScore) {
        this.name = name;
        this.yScore = yScore;
        this.mScore = mScore;
        EnglishScore = englishScore;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", yScore=" + yScore +
                ", mScore=" + mScore +
                ", EnglishScore=" + EnglishScore +
                ", sumScore=" +  this.getSumScore() +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getyScore() {
        return yScore;
    }

    public void setyScore(int yScore) {
        this.yScore = yScore;
    }

    public int getmScore() {
        return mScore;
    }

    public void setmScore(int mScore) {
        this.mScore = mScore;
    }

    public int getEnglishScore() {
        return EnglishScore;
    }

    public void setEnglishScore(int englishScore) {
        EnglishScore = englishScore;
    }

    public int getSumScore(){
        return yScore+mScore+EnglishScore;
    }


    @Override
    public int compareTo(Student o) {
        int result = this.getSumScore() - o.getSumScore();
        result = result == 0 ? this.getyScore() - o.getyScore() : result;
        result = result == 0 ? this.getmScore() - o.getmScore() : result;
        result = result == 0 ? this.getName().compareTo(o.getName()) : result;
        return result*-1;
    }
}
